package com.clientmanage.controller;

import com.clientmanage.domain.vo.serviceEvaluationVo;
import com.clientmanage.domain.resp.PageResult;
import com.clientmanage.domain.resp.Result;
import com.clientmanage.service.IServiceEvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 服务质量评价控制器
 * 实现服务质量评价相关接口
 */
@RestController
@RequestMapping("/service/evaluation")
public class ServiceEvaluationController {
    @Autowired
    private IServiceEvaluationService serviceEvaluationService;

    /**
     * 获取服务质量评价列表
     * 接口地址：GET /service/evaluation/list
     */
    @GetMapping("/list")
    public Result<PageResult<serviceEvaluationVo>> getServiceEvaluationList(
        @RequestParam(required = false) String serviceName,
        @RequestParam(required = false) Integer score,
        @RequestParam(required = false) String date,
        @RequestParam(defaultValue = "1") int pageNum,
        @RequestParam(defaultValue = "10") int pageSize
    ) {
        return Result.success(serviceEvaluationService.pageQuery(serviceName, score, date, pageNum, pageSize));
    }

    /**
     * 新增服务质量评价
     * 接口地址：POST /service/evaluation/add
     */
    @PostMapping("/add")
    public Result<Void> addServiceEvaluation(@RequestBody serviceEvaluationVo vo) {
        serviceEvaluationService.saveOrUpdateServiceEvaluation(vo);
        return Result.success();
    }

    /**
     * 删除服务评价
     * @param id 评价ID
     * @return 操作结果
     */
    @DeleteMapping("/delete/{id}")
    public Result<Void> delete(@PathVariable Long id) {
        serviceEvaluationService.deleteById(String.valueOf(id));
        return Result.success();
    }

    /**
     * 获取服务质量评价统计
     * 接口地址：GET /service/evaluation/stats
     */
    @GetMapping("/stats")
    public Result<Map<String, Object>> getEvaluationStats(
        @RequestParam(required = false) String serviceName,
        @RequestParam(required = false) String date
    ) {
        return Result.success(serviceEvaluationService.getEvaluationStats(serviceName, date));
    }
}
